{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 上周学习内容\n",
    "* A.jupyter notebook 扩展介绍\n",
    "> a. 使用目录，让工作更加便捷   \n",
    "> b. jupyter 的快捷使用\n",
    "* B.Python注释\n",
    "* C.用户输入\n",
    "* D.课本练习\n",
    "\n",
    "## 本周学习内容\n",
    "* A.列表入门\n",
    "* B.列表学习与运用\n",
    "* C.用户输入与格式化打印"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 列表入门"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "> 1. Python 有 6 个序列的内置类型，但最常见的是列表和元组； \n",
    "> 2. 列表都可以进行的操作包括索引，切片，加，乘，检查成员；  \n",
    "> 3. 列表是Python数据类型，它用一个方括号内的逗号分隔值出现；  \n",
    "> 4. 列表的数据项不需要具有相同的类型（列表内可以包含任何类型的元素）。\n",
    "\n",
    "* [补充]：Python 还提供了一个内置的函数 list()，使用它可以将其它数据类型转换为列表类型。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "list1 = [1, 2, 3, 4, 5 ]\n",
    "list2 = [\"a\", \"b\", \"c\", \"d\"]\n",
    "list3 = ['+', 'happy', '五', '1', '%%%']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 列表学习"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "user_data_list = [[\"zhichao\",123435,19],[\"Jack\",463434,23],[\"Alex\",583495,25],[\"Marry\",438294,27]]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 从左往右取值（index & slice）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Alex', 583495, 25]\n",
      "[['zhichao', 123435, 19], ['Jack', 463434, 23], ['Alex', 583495, 25]]\n",
      "[['zhichao', 123435, 19], ['Jack', 463434, 23], ['Alex', 583495, 25]]\n"
     ]
    }
   ],
   "source": [
    "# 从左往右取值（index & slice）\n",
    "print(user_data_list[2])\n",
    "# 切片 slice ，右边的值取不到 例如[0:3] 索引为3的值取不到\n",
    "print(user_data_list[0:3])\n",
    "# 当从0开始取值时，0 可以忽略不写\n",
    "print(user_data_list[:3])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 从右往左取值(index & slice)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Alex', 583495, 25]\n",
      "[['Jack', 463434, 23], ['Alex', 583495, 25]]\n",
      "[]\n",
      "[['Jack', 463434, 23], ['Alex', 583495, 25], ['Marry', 438294, 27]]\n"
     ]
    }
   ],
   "source": [
    "# 从右往左取值(index & slice)\n",
    "print(user_data_list[-2])\n",
    "# 切片 slice ，右边的值取不到 例如[-3:-1] 索引为-1的值取不到\n",
    "print(user_data_list[-3:-1])\n",
    "# 如果取值为空：说明slice写错了 例如[-3:0]\n",
    "# 如果要取到最后一个值，不能写0，直接省略不写\n",
    "print(user_data_list[-3:0])\n",
    "print(user_data_list[-3:])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 重要知识点"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[['zhichao', 123435, 19], ['Jack', 463434, 23], ['Alex', 583495, 25], ['Marry', 438294, 27]]\n",
      "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n",
      "[0, 2, 4]\n"
     ]
    }
   ],
   "source": [
    "print(user_data_list[:])\n",
    "\n",
    "# 步长，list列表slice ：[start:stop:step]\n",
    "'''\n",
    "如果没有指定开始值，则默认为0；\n",
    "如果没有指定结束指，则取列表允许的最大值；\n",
    "如果没有指定步长值，则默认步长为1.\n",
    "'''\n",
    "num = list(range(10))\n",
    "print(num)\n",
    "print(num[0:6:2])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 用户输入和格式化打印"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "name: weihongfen\n",
      "age: 20\n",
      "job: student\n",
      "salary: 10000\n",
      "-----------INFO weihongfen----------\n",
      "name:weihongfen\n",
      "age:20\n",
      "job:student\n",
      "salary:10000\n"
     ]
    }
   ],
   "source": [
    "name = input(\"name: \")\n",
    "age = input(\"age: \")\n",
    "job = input(\"job: \")\n",
    "salary = input(\"salary: \")\n",
    "\n",
    "# name 动态的出现在字符串中,字符串的拼接 用 \"+\" 符号来拼接\n",
    "info = '''-----------INFO '''+ name+ '''----------\n",
    "name:'''+name+'''\n",
    "age:'''+age+'''\n",
    "job:'''+job+'''\n",
    "salary:'''+salary\n",
    "\n",
    "print(info)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 优化字符串拼接 ： 占位符 %s 动态的数据-->变量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "-----------INFO weihongfen----------\n",
      "name:weihongfen\n",
      "age:20\n",
      "job:student\n",
      "salary:10000\n"
     ]
    }
   ],
   "source": [
    "# 优势：1.全部都写在一个大的字符串里面了\n",
    "#       2.省略了 “+”符号\n",
    "# 缺点？ 如果有几百个需要填进去的内容？容易顺序乱掉！出现打印结果的不正确\n",
    "\n",
    "info_占位符 = '''-----------INFO %s----------\n",
    "name:%s\n",
    "age:%s\n",
    "job:%s\n",
    "salary:%s''' %(name,name,age,job,salary)\n",
    "\n",
    "print(info_占位符)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 优化：.format() 格式化 字符串"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "-----------INFO weihongfen----------\n",
      "name:weihongfen\n",
      "age:20\n",
      "job:student\n",
      "salary:10000\n"
     ]
    }
   ],
   "source": [
    "info_format = '''-----------INFO {姓名}----------\n",
    "name:{姓名}\n",
    "age:{年龄}\n",
    "job:{工作}\n",
    "salary:{薪水}'''.format(年龄=age,姓名=name,工作=job,薪水=salary)\n",
    "\n",
    "print(info_format)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### .format()案例"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "https://www.nfu.edu.cn/ztb/index1.htm\n",
      "https://www.nfu.edu.cn/ztb/index2.htm\n",
      "https://www.nfu.edu.cn/ztb/index3.htm\n",
      "https://www.nfu.edu.cn/ztb/index4.htm\n",
      "https://www.nfu.edu.cn/ztb/index5.htm\n",
      "https://www.nfu.edu.cn/ztb/index6.htm\n",
      "https://www.nfu.edu.cn/ztb/index7.htm\n",
      "https://www.nfu.edu.cn/ztb/index8.htm\n",
      "https://www.nfu.edu.cn/ztb/index9.htm\n",
      "https://www.nfu.edu.cn/ztb/index10.htm\n",
      "https://www.nfu.edu.cn/ztb/index11.htm\n",
      "https://www.nfu.edu.cn/ztb/index12.htm\n",
      "https://www.nfu.edu.cn/ztb/index13.htm\n",
      "https://www.nfu.edu.cn/ztb/index14.htm\n",
      "https://www.nfu.edu.cn/ztb/index15.htm\n",
      "https://www.nfu.edu.cn/ztb/index16.htm\n",
      "https://www.nfu.edu.cn/ztb/index17.htm\n",
      "https://www.nfu.edu.cn/ztb/index18.htm\n",
      "https://www.nfu.edu.cn/ztb/index19.htm\n",
      "https://www.nfu.edu.cn/ztb/index20.htm\n",
      "https://www.nfu.edu.cn/ztb/index21.htm\n",
      "https://www.nfu.edu.cn/ztb/index22.htm\n",
      "https://www.nfu.edu.cn/ztb/index23.htm\n",
      "https://www.nfu.edu.cn/ztb/index24.htm\n",
      "https://www.nfu.edu.cn/ztb/index25.htm\n",
      "https://www.nfu.edu.cn/ztb/index26.htm\n"
     ]
    }
   ],
   "source": [
    "url = \"https://www.nfu.edu.cn/\"  #官网的域名\n",
    "# 目标获取高教动态的所有url链接\n",
    "高教动态 = \"gjdt\"\n",
    "url_页面 = \".htm\"\n",
    "url_页面细节不变 = \"/index\"\n",
    "\n",
    "# for i in range(1,27):\n",
    "#     完整的高教动态所有页面url = url+高教动态+ url_页面细节不变 + str(i)+url_页面\n",
    "#     print(完整的高教动态所有页面url)\n",
    "\n",
    "for i in range(1,27):\n",
    "    完整的高教动态所有页面url = \"https://www.nfu.edu.cn/{新闻}/index{页码}.htm\".format(页码=i,新闻=\"ztb\")\n",
    "    print(完整的高教动态所有页面url)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
